from flask import Flask
from flask import request

import tushare as ts
import json


app = Flask(__name__)

# stock index more
@app.route('/stock_index', methods=['GET', 'POST'])
def stock_index():
    # if request.method == 'GET':
    df = ts.get_index()
    # print df.head(3).to_json(orient='records')
    return df.to_json(orient='records')

# now
@app.route('/now_index', methods=['GET', 'POST'])
def now_index():
    df = ts.get_realtime_quotes(['sh','sz','hs300','sz50','zxb','cyb'])
    return df.to_json(orient='records')

# news
@app.route('/news', methods=['GET', 'POST'])
def news():
    df = ts.get_latest_news(top=10,show_content=True)
    return df.to_json(orient='records')
